cmake_minimum_required (VERSION 2.6)
project ("Distribuidos")

set(SRC_DIR ./)
set(SRC_DIR_MARIANO ${SRC_DIR}mariano/)
set(OUT_DIR "out/")
set(TEST_OUT_DIR ${OUT_DIR}tests/)
set(MOCK_OUT_DIR ${OUT_DIR}mocks/)
set(RPCSERVER_OUT_DIR ${OUT_DIR}rpcserver/)
set(BROKER_OUT_DIR    ${OUT_DIR}broker/)
set(HOST_OUT_DIR      ${OUT_DIR}host/)
set(CMAKE_BUILD_TYPE Debug)

include_directories("${SRC_DIR}")
include_directories("${SRC_DIR}IPC")
include_directories("${SRC_DIR}common")
include_directories("${SRC_DIR}middleware")
include_directories("${SRC_DIR_MARIANO}")
include_directories("${SRC_DIR_MARIANO}comun")
include_directories("${SRC_DIR_MARIANO}api")
include_directories("${SRC_DIR_MARIANO}middleware/controladores")
include_directories("${SRC_DIR_MARIANO}comun/objetosComunes")
include_directories("${SRC_DIR_MARIANO}objetosCompartidos")

file(MAKE_DIRECTORY ${OUT_DIR})
file(MAKE_DIRECTORY ${OUT_DIR}application/)
file(MAKE_DIRECTORY ${MOCK_OUT_DIR})
file(MAKE_DIRECTORY ${TEST_OUT_DIR})
file(MAKE_DIRECTORY ${TEST_OUT_DIR}ipc)


AUX_SOURCE_DIRECTORY ("${SRC_DIR}common" COMMON_LIB_SRC)
ADD_LIBRARY( common_lib STATIC ${COMMON_LIB_SRC})
AUX_SOURCE_DIRECTORY ("${SRC_DIR}IPC" IPC_LIB_SRC)
ADD_LIBRARY( ipc_lib STATIC ${IPC_LIB_SRC})
AUX_SOURCE_DIRECTORY ("${SRC_DIR}logger" LOGGER_LIB_SRC)
ADD_LIBRARY( logger_lib STATIC ${LOGGER_LIB_SRC})
AUX_SOURCE_DIRECTORY ("${SRC_DIR}application" APPLICATION_LIB_SRC)
ADD_LIBRARY( application_lib STATIC ${APPLICATION_LIB_SRC})
AUX_SOURCE_DIRECTORY ("${SRC_DIR}middleware" MIDDLEWARE_LIB_SRC)
ADD_LIBRARY( middleware_lib STATIC ${MIDDLEWARE_LIB_SRC})

target_link_libraries(middleware_lib dsm_lib)

AUX_SOURCE_DIRECTORY ("${SRC_DIR}channel_common" CHANNEL_COMMON_LIB_SRC)
ADD_LIBRARY( channel_common_lib STATIC ${CHANNEL_COMMON_LIB_SRC})


AUX_SOURCE_DIRECTORY ("${SRC_DIR}common" COMMON_SRC)
AUX_SOURCE_DIRECTORY ("${SRC_DIR}IPC" COMMON_SRC)
AUX_SOURCE_DIRECTORY ("${SRC_DIR}logger" COMMON_SRC)
AUX_SOURCE_DIRECTORY ("${SRC_DIR}application" COMMON_SRC)
AUX_SOURCE_DIRECTORY ("${SRC_DIR}middleware" COMMON_SRC)
AUX_SOURCE_DIRECTORY ("${SRC_DIR}channel_common" COMMON_SRC)


AUX_SOURCE_DIRECTORY ("${SRC_DIR_MARIANO}comun" MARIANO_COMMON_SRC)
ADD_LIBRARY( mariano_common_lib STATIC ${MARIANO_COMMON_SRC})
#AUX_SOURCE_DIRECTORY ("${SRC_DIR_MARIANO}api" MARIANO_API_SRC)
#ADD_LIBRARY( mariano_api_lib STATIC ${MARIANO_API_SRC})
#AUX_SOURCE_DIRECTORY ("${SRC_DIR_MARIANO}middleware/controladores" MARIANO_CONTROLADORES_SRC)
#ADD_LIBRARY( mariano_controladores_lib STATIC ${MARIANO_CONTROLADORES_SRC})
#AUX_SOURCE_DIRECTORY ("${SRC_DIR_MARIANO}comun/objetosComunes" MARIANO_COMMON_OBJS_SRC)
#ADD_LIBRARY( mariano_common_objs_lib STATIC ${MARIANO_COMMON_OBJS_SRC})
AUX_SOURCE_DIRECTORY ("${SRC_DIR_MARIANO}objetosCompartidos" MARIANO_SHARED_OBJS_SRC)
ADD_LIBRARY( mariano_shared_objs_lib STATIC ${MARIANO_SHARED_OBJS_SRC})

AUX_SOURCE_DIRECTORY ("${SRC_DIR}channel_common/agent_address_service" AGENT_ADDRESS_SRC)
ADD_LIBRARY( agent_address_lib STATIC ${AGENT_ADDRESS_SRC})
AUX_SOURCE_DIRECTORY ("${SRC_DIR}channel_common/routing_tables" ROUTING_SRC)
ADD_LIBRARY( routing_tables_lib STATIC ${ROUTING_SRC})

#add_executable(${TEST_OUT_DIR}ipc/mqinit ${SRC_DIR}tests/msgqueue/mqinit.cpp ${SRC_DIR}tests/msgqueue/MyMessage.cpp ${COMMON_SRC}) 
#add_executable(${TEST_OUT_DIR}ipc/mqsend ${SRC_DIR}tests/msgqueue/mqsend.cpp ${SRC_DIR}tests/msgqueue/MyMessage.cpp ${COMMON_SRC}) 


#---------Routing service------
add_executable(${TEST_OUT_DIR}routing_resolve_agent ${SRC_DIR}channel_common/routing_tables/test/routing_resolve_agent.cpp)
target_link_libraries(${TEST_OUT_DIR}routing_resolve_agent routing_tables_lib ipc_lib common_lib)
add_executable(${TEST_OUT_DIR}routing_register_agent ${SRC_DIR}channel_common/routing_tables/test/routing_register_agent.cpp)
target_link_libraries(${TEST_OUT_DIR}routing_register_agent routing_tables_lib ipc_lib common_lib)
add_executable(${TEST_OUT_DIR}routing_register_host ${SRC_DIR}channel_common/routing_tables/test/routing_register_host.cpp)
target_link_libraries(${TEST_OUT_DIR}routing_register_host routing_tables_lib ipc_lib common_lib)
add_executable(${TEST_OUT_DIR}routing_resolve_host ${SRC_DIR}channel_common/routing_tables/test/routing_resolve_host.cpp)
target_link_libraries(${TEST_OUT_DIR}routing_resolve_host routing_tables_lib ipc_lib common_lib)

add_executable(${OUT_DIR}routing_server ${SRC_DIR}channel_common/routing_tables/server/routing_svc.c)
target_link_libraries(${OUT_DIR}routing_server routing_tables_lib ipc_lib common_lib)

#-----------Agent address service
add_executable(${TEST_OUT_DIR}agent_address_register_static ${SRC_DIR}channel_common/agent_address_service/test/agent_address_register_static.cpp)
target_link_libraries(${TEST_OUT_DIR}agent_address_register_static agent_address_lib routing_tables_lib ipc_lib common_lib)
add_executable(${TEST_OUT_DIR}agent_address_register_dynamic ${SRC_DIR}channel_common/agent_address_service/test/agent_address_register_dynamic.cpp)
target_link_libraries(${TEST_OUT_DIR}agent_address_register_dynamic agent_address_lib routing_tables_lib ipc_lib common_lib)
add_executable(${TEST_OUT_DIR}agent_address_unregister ${SRC_DIR}channel_common/agent_address_service/test/agent_address_unregister.cpp)
target_link_libraries(${TEST_OUT_DIR}agent_address_unregister agent_address_lib routing_tables_lib ipc_lib common_lib)
add_executable(${TEST_OUT_DIR}agent_address_resolve ${SRC_DIR}channel_common/agent_address_service/test/agent_address_resolve.cpp)
target_link_libraries(${TEST_OUT_DIR}agent_address_resolve agent_address_lib routing_tables_lib ipc_lib common_lib)
add_executable(${TEST_OUT_DIR}agent_address_get_address ${SRC_DIR}channel_common/agent_address_service/test/agent_address_get_address.cpp)
target_link_libraries(${TEST_OUT_DIR}agent_address_get_address agent_address_lib routing_tables_lib ipc_lib common_lib)

#server
add_executable(${OUT_DIR}agent_address_server ${SRC_DIR}channel_common/agent_address_service/server/agent_address_service_svc.c)
target_link_libraries(${OUT_DIR}agent_address_server agent_address_lib routing_tables_lib ipc_lib common_lib)


#---------Agent channels
add_executable(${OUT_DIR}channel_in_agente ${SRC_DIR}channel/channel_in_agente.cpp)
target_link_libraries(${OUT_DIR}channel_in_agente channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib) 
add_executable(${OUT_DIR}channel_out_agente ${SRC_DIR}channel/channel_out_agente.cpp) 
target_link_libraries(${OUT_DIR}channel_out_agente channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib)


#--------Broker channels
add_executable(${OUT_DIR}channel_in_broker ${SRC_DIR}channel/channel_in_broker.cpp)
target_link_libraries(${OUT_DIR}channel_in_broker routing_tables_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}channel_out_broker ${SRC_DIR}channel/channel_out_broker.cpp)
target_link_libraries(${OUT_DIR}channel_out_broker channel_common_lib routing_tables_lib application_lib middleware_lib logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}launcher_canales_cli ${SRC_DIR}channel/LauncherCanalesCliente.cpp)
target_link_libraries(${OUT_DIR}launcher_canales_cli channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}servidor_in_broker ${SRC_DIR}channel/ServidorEntradaBroker.cpp)
target_link_libraries(${OUT_DIR}servidor_in_broker channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}servidor_out_broker ${SRC_DIR}channel/ServidorSalidaBroker.cpp)
target_link_libraries(${OUT_DIR}servidor_out_broker channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib)


#--------Mux
add_executable(${OUT_DIR}mq_mux ${SRC_DIR}capa_servicios_distribuidos/queue/QueueMux.cpp)
target_link_libraries(${OUT_DIR}mq_mux channel_common_lib routing_tables_lib application_lib middleware_lib logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}mq_demux ${SRC_DIR}capa_servicios_distribuidos/queue/QueueDemux.cpp)
target_link_libraries(${OUT_DIR}mq_demux channel_common_lib routing_tables_lib application_lib middleware_lib logger_lib ipc_lib common_lib)

#--------Mocks
add_executable(${MOCK_OUT_DIR}mock_put_queue ${SRC_DIR}channel/mock_put_queue.cpp)
target_link_libraries(${MOCK_OUT_DIR}mock_put_queue channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib)
add_executable(${MOCK_OUT_DIR}mock_get_queue ${SRC_DIR}channel/mock_get_queue.cpp)
target_link_libraries(${MOCK_OUT_DIR}mock_get_queue channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib)
add_executable(${MOCK_OUT_DIR}mock_pedido_completo ${SRC_DIR}control/MockPedidoCompleto.cpp)
target_link_libraries(${MOCK_OUT_DIR}mock_pedido_completo channel_common_lib routing_tables_lib application_lib middleware_lib agent_address_lib logger_lib ipc_lib common_lib)
add_executable(${MOCK_OUT_DIR}mockRobot14 ${SRC_DIR}control/mockRobot14.cpp)
target_link_libraries(${MOCK_OUT_DIR}mockRobot14 application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)
add_executable(${MOCK_OUT_DIR}pedidos ${SRC_DIR}control/MockPedidosProduccion.cpp)
target_link_libraries(${MOCK_OUT_DIR}pedidos application_lib middleware_lib logger_lib ipc_lib common_lib)

#--------Broker Launchers/Terminators
add_executable(${OUT_DIR}channel_launcher_broker ${SRC_DIR}channel/channel_launcher_broker.cpp)
target_link_libraries(${OUT_DIR}channel_launcher_broker agent_address_lib routing_tables_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}channel_terminator_broker ${SRC_DIR}channel/channel_terminator_broker.cpp)
target_link_libraries(${OUT_DIR}channel_terminator_broker agent_address_lib routing_tables_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}interbroker_channel_launcher ${SRC_DIR}channel/interbroker_channel_launcher.cpp)
target_link_libraries(${OUT_DIR}interbroker_channel_launcher channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}terminator_general_brokers ${SRC_DIR}channel/terminator_general_brokers.cpp)
target_link_libraries(${OUT_DIR}terminator_general_brokers channel_common_lib  agent_address_lib routing_tables_lib application_lib middleware_lib logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}launcher_general_brokers ${SRC_DIR}channel/launcher_general_brokers.cpp)
target_link_libraries(${OUT_DIR}launcher_general_brokers channel_common_lib agent_address_lib routing_tables_lib application_lib middleware_lib logger_lib ipc_lib common_lib)

#--------launcher para hosts----------
add_executable(${OUT_DIR}launcher_despacho ${SRC_DIR}launchers/launcher_despacho.cpp)
target_link_libraries(${OUT_DIR}launcher_despacho channel_common_lib routing_tables_lib application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}terminator_despacho ${SRC_DIR}launchers/terminator_despacho.cpp)
target_link_libraries(${OUT_DIR}terminator_despacho channel_common_lib routing_tables_lib application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}launcher_cliente ${SRC_DIR}launchers/launcher_cliente.cpp)
target_link_libraries(${OUT_DIR}launcher_cliente channel_common_lib routing_tables_lib application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}terminator_cliente ${SRC_DIR}launchers/terminator_cliente.cpp)
target_link_libraries(${OUT_DIR}terminator_cliente channel_common_lib routing_tables_lib application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}launcher_adpt ${SRC_DIR}launchers/launcher_adpt.cpp)
target_link_libraries(${OUT_DIR}launcher_adpt channel_common_lib routing_tables_lib application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}terminator_adpt ${SRC_DIR}launchers/terminator_adpt.cpp)
target_link_libraries(${OUT_DIR}terminator_adpt channel_common_lib routing_tables_lib application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}launcher_vendedor ${SRC_DIR}launchers/launcher_vendedor.cpp)
target_link_libraries(${OUT_DIR}launcher_vendedor channel_common_lib routing_tables_lib application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}terminator_vendedor ${SRC_DIR}launchers/terminator_vendedor.cpp)
target_link_libraries(${OUT_DIR}terminator_vendedor channel_common_lib routing_tables_lib application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)

### NUEVOS A MERGEAR
add_executable(${OUT_DIR}launcher_adp ${SRC_DIR}launchers/launcher_adp.cpp)
target_link_libraries(${OUT_DIR}launcher_adp channel_common_lib routing_tables_lib application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)

add_executable(${OUT_DIR}launcher_agv ${SRC_DIR}launchers/launcher_agv.cpp)
target_link_libraries(${OUT_DIR}launcher_agv channel_common_lib routing_tables_lib application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)

add_executable(${OUT_DIR}launcher_robot5 ${SRC_DIR}launchers/launcher_robot5.cpp)
target_link_libraries(${OUT_DIR}launcher_robot5 channel_common_lib routing_tables_lib application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)

add_executable(${OUT_DIR}launcher_robot11 ${SRC_DIR}launchers/launcher_robot11.cpp)
target_link_libraries(${OUT_DIR}launcher_robot11 channel_common_lib routing_tables_lib application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)

add_executable(${OUT_DIR}launcher_robot12 ${SRC_DIR}launchers/launcher_robot12.cpp)
target_link_libraries(${OUT_DIR}launcher_robot12 channel_common_lib routing_tables_lib application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)

add_executable(${OUT_DIR}terminator_adp ${SRC_DIR}launchers/terminator_adp.cpp)
target_link_libraries(${OUT_DIR}terminator_adp channel_common_lib routing_tables_lib application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)

add_executable(${OUT_DIR}terminator_agv ${SRC_DIR}launchers/terminator_agv.cpp)
target_link_libraries(${OUT_DIR}terminator_agv channel_common_lib routing_tables_lib application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)

add_executable(${OUT_DIR}terminator_robot5 ${SRC_DIR}launchers/terminator_robot5.cpp)
target_link_libraries(${OUT_DIR}terminator_robot5 channel_common_lib routing_tables_lib application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)

add_executable(${OUT_DIR}terminator_robot11 ${SRC_DIR}launchers/terminator_robot11.cpp)
target_link_libraries(${OUT_DIR}terminator_robot11 channel_common_lib routing_tables_lib application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)

add_executable(${OUT_DIR}terminator_robot12 ${SRC_DIR}launchers/terminator_robot12.cpp)
target_link_libraries(${OUT_DIR}terminator_robot12 channel_common_lib routing_tables_lib application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)

### FIN NUEVOS A MERGEAR 

#--------Application
add_executable(${OUT_DIR}cliente ${SRC_DIR}control/cliente.cpp)
target_link_libraries(${OUT_DIR}cliente application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}vendedor ${SRC_DIR}control/vendedor.cpp)
target_link_libraries(${OUT_DIR}vendedor application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}adpt ${SRC_DIR}control/adpt.cpp)
target_link_libraries(${OUT_DIR}adpt dsm_lib application_lib middleware_lib agent_address_lib logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}despacho ${SRC_DIR}control/despacho.cpp)
target_link_libraries(${OUT_DIR}despacho application_lib middleware_lib agent_address_lib  logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}robot16 ${SRC_DIR}control/robot16.cpp)
target_link_libraries(${OUT_DIR}robot16 dsm_lib application_lib middleware_lib agent_address_lib mariano_shared_objs_lib mariano_common_lib logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}launcher ${SRC_DIR}control/launcher.cpp) 
target_link_libraries(${OUT_DIR}launcher application_lib middleware_lib agent_address_lib  mariano_shared_objs_lib mariano_common_lib logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}terminator ${SRC_DIR}control/terminator.cpp) 
target_link_libraries(${OUT_DIR}terminator agent_address_lib application_lib middleware_lib agent_address_lib  mariano_shared_objs_lib mariano_common_lib logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}agv ${SRC_DIR}control/agv.cpp) 
target_link_libraries(${OUT_DIR}agv dsm_lib application_lib middleware_lib agent_address_lib logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}robot5 ${SRC_DIR}control/robot5.cpp) 
target_link_libraries(${OUT_DIR}robot5 dsm_lib application_lib middleware_lib agent_address_lib logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}adp ${SRC_DIR}control/adp.cpp) 
target_link_libraries(${OUT_DIR}adp dsm_lib application_lib middleware_lib agent_address_lib logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}robot11 ${SRC_DIR}control/robot11.cpp)
target_link_libraries(${OUT_DIR}robot11 dsm_lib application_lib middleware_lib agent_address_lib mariano_shared_objs_lib mariano_common_lib logger_lib ipc_lib common_lib)
add_executable(${OUT_DIR}robot12 ${SRC_DIR}control/robot12.cpp)
target_link_libraries(${OUT_DIR}robot12 dsm_lib mariano_shared_objs_lib mariano_common_lib application_lib middleware_lib agent_address_lib logger_lib ipc_lib common_lib)


#----Application Mariano------
add_executable(${HOST_OUT_DIR}launcherM     ${SRC_DIR_MARIANO}aplicacion/launcher.cpp)
add_executable(${HOST_OUT_DIR}controlR11A   ${SRC_DIR_MARIANO}aplicacion/controlRobot11A.cpp)
add_executable(${HOST_OUT_DIR}controlR11B   ${SRC_DIR_MARIANO}aplicacion/controlRobot11B.cpp)
add_executable(${HOST_OUT_DIR}controlR14    ${SRC_DIR_MARIANO}aplicacion/controlRobot14.cpp)
add_executable(${HOST_OUT_DIR}controlR16    ${SRC_DIR_MARIANO}aplicacion/controlRobot16.cpp)
add_executable(${HOST_OUT_DIR}terminatorM   ${SRC_DIR_MARIANO}aplicacion/terminator.cpp)
target_link_libraries(${HOST_OUT_DIR}launcherM    dsm_lib mariano_shared_objs_lib mariano_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib)
target_link_libraries(${HOST_OUT_DIR}controlR11A  dsm_lib mariano_shared_objs_lib mariano_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib)
target_link_libraries(${HOST_OUT_DIR}controlR11B  dsm_lib mariano_shared_objs_lib mariano_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib)
target_link_libraries(${HOST_OUT_DIR}controlR14   dsm_lib mariano_shared_objs_lib mariano_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib)
target_link_libraries(${HOST_OUT_DIR}controlR16   dsm_lib mariano_shared_objs_lib mariano_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib)
target_link_libraries(${HOST_OUT_DIR}terminatorM  dsm_lib mariano_shared_objs_lib mariano_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib)

target_link_libraries(mariano_common_lib common_lib)

file(MAKE_DIRECTORY ${HOST_OUT_DIR})
file(MAKE_DIRECTORY ${BROKER_OUT_DIR})
file(MAKE_DIRECTORY ${RPCSERVER_OUT_DIR})

#--------Servicio DNS--------
include_directories("${SRC_DIR}dns")
AUX_SOURCE_DIRECTORY ("${SRC_DIR}dns" DNS_LIB_SRC)
ADD_LIBRARY( dns_lib STATIC ${DNS_LIB_SRC})

add_executable(${RPCSERVER_OUT_DIR}dnsServer    ${SRC_DIR}dns/server/dns_svc.c)
add_executable(${TEST_OUT_DIR}dnsRegister       ${SRC_DIR}dns/test/dnsRegister.cpp)
add_executable(${TEST_OUT_DIR}dnsResolve        ${SRC_DIR}dns/test/dnsResolve.cpp)
add_executable(${TEST_OUT_DIR}dnsUnregister     ${SRC_DIR}dns/test/dnsUnregister.cpp)
add_executable(${TEST_OUT_DIR}dnsTest           ${SRC_DIR}dns/test/dnsTest.cpp)
target_link_libraries(${RPCSERVER_OUT_DIR}dnsServer   dns_lib application_lib middleware_lib logger_lib ipc_lib mariano_common_lib)
target_link_libraries(${TEST_OUT_DIR}dnsRegister      dns_lib application_lib middleware_lib logger_lib ipc_lib mariano_common_lib)
target_link_libraries(${TEST_OUT_DIR}dnsResolve       dns_lib application_lib middleware_lib logger_lib ipc_lib mariano_common_lib)
target_link_libraries(${TEST_OUT_DIR}dnsUnregister    dns_lib application_lib middleware_lib logger_lib ipc_lib mariano_common_lib)
target_link_libraries(${TEST_OUT_DIR}dnsTest          dns_lib application_lib middleware_lib logger_lib ipc_lib mariano_common_lib)

file(COPY ${SRC_DIR}dns/dnsTable.ini DESTINATION ${RPCSERVER_OUT_DIR})


#--------Servicio Numerador--------
include_directories("${SRC_DIR}numerador")
AUX_SOURCE_DIRECTORY ("${SRC_DIR}numerador" NUMERADOR_LIB_SRC)
ADD_LIBRARY( numerador_lib STATIC ${NUMERADOR_LIB_SRC})

add_executable(${RPCSERVER_OUT_DIR}numeradorServer  ${SRC_DIR}numerador/server/numerador_svc.c)
add_executable(${TEST_OUT_DIR}numeradorTest         ${SRC_DIR}numerador/test/numerador.cpp)
target_link_libraries(${RPCSERVER_OUT_DIR}numeradorServer  numerador_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${TEST_OUT_DIR}numeradorTest         numerador_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)

file(COPY ${SRC_DIR}numerador/numerador.ini     DESTINATION ${RPCSERVER_OUT_DIR})

#--------Servicio RoutingTable--------
include_directories("${SRC_DIR}routingTable")
AUX_SOURCE_DIRECTORY ("${SRC_DIR}routingTable" RT_LIB_SRC)
ADD_LIBRARY( rt_lib STATIC ${RT_LIB_SRC})

add_executable(${RPCSERVER_OUT_DIR}rtServer      ${SRC_DIR}routingTable/server/routing_table_svc.c)
add_executable(${TEST_OUT_DIR}rt_getRoute        ${SRC_DIR}routingTable/test/rt_getRoute.cpp)
add_executable(${TEST_OUT_DIR}rt_setRoute        ${SRC_DIR}routingTable/test/rt_setRoute.cpp)
target_link_libraries(${RPCSERVER_OUT_DIR}rtServer   rt_lib application_lib middleware_lib logger_lib ipc_lib mariano_common_lib)
target_link_libraries(${TEST_OUT_DIR}rt_getRoute     rt_lib application_lib middleware_lib logger_lib ipc_lib mariano_common_lib)
target_link_libraries(${TEST_OUT_DIR}rt_setRoute     rt_lib application_lib middleware_lib logger_lib ipc_lib mariano_common_lib)

file(COPY ${SRC_DIR}routingTable/routingTable.ini DESTINATION ${RPCSERVER_OUT_DIR})

add_executable(${RPCSERVER_OUT_DIR}launcher_rpcserver     ${SRC_DIR}launchers/launcher_rpcserver.cpp)
add_executable(${RPCSERVER_OUT_DIR}terminator_rpcserver   ${SRC_DIR}launchers/terminator_rpcserver.cpp)
target_link_libraries(${RPCSERVER_OUT_DIR}launcher_rpcserver   dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${RPCSERVER_OUT_DIR}terminator_rpcserver dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)

#--------Servicio de Cola Remota--------
include_directories("${SRC_DIR}socket")
AUX_SOURCE_DIRECTORY ("${SRC_DIR}socket" SOCKET_LIB_SRC)
ADD_LIBRARY( socket_lib STATIC ${SOCKET_LIB_SRC})

include_directories("${SRC_DIR}colaRemota")
AUX_SOURCE_DIRECTORY ("${SRC_DIR}colaRemota" COLAREMOTA_LIB_SRC)
ADD_LIBRARY( colaRemota_lib STATIC ${COLAREMOTA_LIB_SRC})

add_executable(${BROKER_OUT_DIR}launcherServicioColaRemota   ${SRC_DIR}colaRemota/broker/launcherServicioColaRemota.cpp)
add_executable(${BROKER_OUT_DIR}receptor                     ${SRC_DIR}colaRemota/broker/receptor.cpp)
add_executable(${BROKER_OUT_DIR}transmisor                   ${SRC_DIR}colaRemota/broker/transmisor.cpp)
add_executable(${BROKER_OUT_DIR}servidorEntrada              ${SRC_DIR}colaRemota/broker/servidorEntrada.cpp)
add_executable(${BROKER_OUT_DIR}servidorSalida               ${SRC_DIR}colaRemota/broker/servidorSalida.cpp)
add_executable(${BROKER_OUT_DIR}terminatorServicioColaRemota ${SRC_DIR}colaRemota/broker/terminatorServicioColaRemota.cpp)
target_link_libraries(${BROKER_OUT_DIR}launcherServicioColaRemota   colaRemota_lib socket_lib rt_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${BROKER_OUT_DIR}receptor                     colaRemota_lib socket_lib rt_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${BROKER_OUT_DIR}transmisor                   colaRemota_lib socket_lib rt_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${BROKER_OUT_DIR}servidorEntrada              colaRemota_lib socket_lib rt_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${BROKER_OUT_DIR}servidorSalida               colaRemota_lib socket_lib rt_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${BROKER_OUT_DIR}terminatorServicioColaRemota colaRemota_lib socket_lib rt_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)

include_directories("${SRC_DIR}colaRemota/host")
add_executable(${TEST_OUT_DIR}rmq_receiver      ${SRC_DIR}colaRemota/test/receiver.cpp)
add_executable(${TEST_OUT_DIR}rmq_sender        ${SRC_DIR}colaRemota/test/sender.cpp)
target_link_libraries(${TEST_OUT_DIR}rmq_receiver colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${TEST_OUT_DIR}rmq_sender   colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)

#Copio los archivos de configuracion!
file(COPY ${SRC_DIR}archivosConfiguracion/config.ini DESTINATION ${BROKER_OUT_DIR})
file(COPY ${SRC_DIR}archivosConfiguracion/brokerlist DESTINATION ${BROKER_OUT_DIR})
file(COPY ${SRC_DIR}archivosConfiguracion/config.ini DESTINATION ${HOST_OUT_DIR})
file(COPY ${SRC_DIR}archivosConfiguracion/brokerlist DESTINATION ${HOST_OUT_DIR})
file(COPY ${SRC_DIR}archivosConfiguracion/config.ini DESTINATION ${TEST_OUT_DIR})
file(COPY ${SRC_DIR}archivosConfiguracion/brokerlist DESTINATION ${TEST_OUT_DIR})

#--------DistributedSharedMemoryManager--------

include_directories("${SRC_DIR}distributed_shared_memory/comun")
AUX_SOURCE_DIRECTORY ("${SRC_DIR}distributed_shared_memory/comun" DSM_LIB_SRC)
ADD_LIBRARY( dsm_lib STATIC ${DSM_LIB_SRC})

add_executable(${BROKER_OUT_DIR}dsmGestorEntrega        ${SRC_DIR}distributed_shared_memory/broker/dsmGestorEntrega.cpp)
add_executable(${BROKER_OUT_DIR}dsmGestorPedidos        ${SRC_DIR}distributed_shared_memory/broker/dsmGestorPedidos.cpp)
add_executable(${BROKER_OUT_DIR}dsmGestorToken          ${SRC_DIR}distributed_shared_memory/broker/dsmGestorToken.cpp)
add_executable(${BROKER_OUT_DIR}dsm_launcher_broker     ${SRC_DIR}distributed_shared_memory/broker/dsm_launcher_broker.cpp)
add_executable(${BROKER_OUT_DIR}dsm_terminator_broker   ${SRC_DIR}distributed_shared_memory/broker/dsm_terminator_broker.cpp)
target_link_libraries(${BROKER_OUT_DIR}dsmGestorEntrega      colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${BROKER_OUT_DIR}dsmGestorPedidos      colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${BROKER_OUT_DIR}dsmGestorToken        colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${BROKER_OUT_DIR}dsm_launcher_broker   colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${BROKER_OUT_DIR}dsm_terminator_broker colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)

add_executable(${HOST_OUT_DIR}dsmReleaser           ${SRC_DIR}distributed_shared_memory/host/dsmReleaser.cpp)
add_executable(${HOST_OUT_DIR}dsmRequestor          ${SRC_DIR}distributed_shared_memory/host/dsmRequestor.cpp)
add_executable(${HOST_OUT_DIR}dsm_launcher_host     ${SRC_DIR}distributed_shared_memory/host/dsm_launcher_host.cpp)
add_executable(${HOST_OUT_DIR}dsm_terminator_host   ${SRC_DIR}distributed_shared_memory/host/dsm_terminator_host.cpp)
add_executable(${HOST_OUT_DIR}dsm_creador_canales   ${SRC_DIR}distributed_shared_memory/host/dsm_creador_canales.cpp)
target_link_libraries(${HOST_OUT_DIR}dsmReleaser         colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib mariano_shared_objs_lib)
target_link_libraries(${HOST_OUT_DIR}dsmRequestor        colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib mariano_shared_objs_lib)
target_link_libraries(${HOST_OUT_DIR}dsm_launcher_host   colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${HOST_OUT_DIR}dsm_terminator_host colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${HOST_OUT_DIR}dsm_creador_canales colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)

add_executable(${TEST_OUT_DIR}dsm_test              ${SRC_DIR}distributed_shared_memory/test/dsm_test.cpp)
add_executable(${TEST_OUT_DIR}dsm_launcher_test     ${SRC_DIR}distributed_shared_memory/test/dsm_launcher_test.cpp)
add_executable(${TEST_OUT_DIR}dsm_terminator_test   ${SRC_DIR}distributed_shared_memory/test/dsm_terminator_test.cpp)
target_link_libraries(${TEST_OUT_DIR}dsm_test            dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${TEST_OUT_DIR}dsm_launcher_test   dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${TEST_OUT_DIR}dsm_terminator_test dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)

add_executable(${BROKER_OUT_DIR}launcher_broker     ${SRC_DIR}launchers/launcher_broker.cpp)
add_executable(${BROKER_OUT_DIR}terminator_broker   ${SRC_DIR}launchers/terminator_broker.cpp)
target_link_libraries(${BROKER_OUT_DIR}launcher_broker   dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${BROKER_OUT_DIR}terminator_broker dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)


#--------Gestores de Tokens--------
add_executable(${BROKER_OUT_DIR}gestorToken1   ${SRC_DIR}distributed_shared_memory/broker/gestoresToken/gestorToken1.cpp)
add_executable(${BROKER_OUT_DIR}gestorToken2   ${SRC_DIR}distributed_shared_memory/broker/gestoresToken/gestorToken2.cpp)
add_executable(${BROKER_OUT_DIR}gestorToken3   ${SRC_DIR}distributed_shared_memory/broker/gestoresToken/gestorToken3.cpp)
add_executable(${BROKER_OUT_DIR}gestorToken4   ${SRC_DIR}distributed_shared_memory/broker/gestoresToken/gestorToken4.cpp)
add_executable(${BROKER_OUT_DIR}gestorToken5   ${SRC_DIR}distributed_shared_memory/broker/gestoresToken/gestorToken5.cpp)
add_executable(${BROKER_OUT_DIR}gestorToken6   ${SRC_DIR}distributed_shared_memory/broker/gestoresToken/gestorToken6.cpp)
add_executable(${BROKER_OUT_DIR}gestorToken7   ${SRC_DIR}distributed_shared_memory/broker/gestoresToken/gestorToken7.cpp)
add_executable(${BROKER_OUT_DIR}gestorToken8   ${SRC_DIR}distributed_shared_memory/broker/gestoresToken/gestorToken8.cpp)
add_executable(${BROKER_OUT_DIR}gestorToken9   ${SRC_DIR}distributed_shared_memory/broker/gestoresToken/gestorToken9.cpp)
add_executable(${BROKER_OUT_DIR}gestorToken10   ${SRC_DIR}distributed_shared_memory/broker/gestoresToken/gestorToken10.cpp)
add_executable(${BROKER_OUT_DIR}gestorToken11   ${SRC_DIR}distributed_shared_memory/broker/gestoresToken/gestorToken11.cpp)

target_link_libraries(${BROKER_OUT_DIR}gestorToken1     dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${BROKER_OUT_DIR}gestorToken2     dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${BROKER_OUT_DIR}gestorToken3     dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${BROKER_OUT_DIR}gestorToken4     dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${BROKER_OUT_DIR}gestorToken5     dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${BROKER_OUT_DIR}gestorToken6     dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${BROKER_OUT_DIR}gestorToken7     dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${BROKER_OUT_DIR}gestorToken8     dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${BROKER_OUT_DIR}gestorToken9     dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${BROKER_OUT_DIR}gestorToken10     dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${BROKER_OUT_DIR}gestorToken11     dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)

#--------Distributed Semaphore--------
add_executable(${HOST_OUT_DIR}dsSignaler        ${SRC_DIR}distributed_semaphore/dsSignaler.cpp)
add_executable(${HOST_OUT_DIR}dsWaiter          ${SRC_DIR}distributed_semaphore/dsWaiter.cpp)
target_link_libraries(${HOST_OUT_DIR}dsSignaler dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${HOST_OUT_DIR}dsWaiter   dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)

#--------Launchers Mariano--------
add_executable(${HOST_OUT_DIR}launcher_host             ${SRC_DIR}launchers/launcher_host.cpp )
add_executable(${HOST_OUT_DIR}launcher_robot11a         ${SRC_DIR}launchers/launcher_robot11a.cpp )
add_executable(${HOST_OUT_DIR}launcher_robot11b         ${SRC_DIR}launchers/launcher_robot11b.cpp )
add_executable(${HOST_OUT_DIR}launcher_robot14          ${SRC_DIR}launchers/launcher_robot14.cpp  )
add_executable(${HOST_OUT_DIR}launcher_robot16          ${SRC_DIR}launchers/launcher_robot16.cpp  )
add_executable(${HOST_OUT_DIR}terminator_host           ${SRC_DIR}launchers/terminator_host.cpp )
target_link_libraries(${HOST_OUT_DIR}launcher_host      mariano_shared_objs_lib dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${HOST_OUT_DIR}launcher_robot11a  mariano_shared_objs_lib dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${HOST_OUT_DIR}launcher_robot11b  mariano_shared_objs_lib dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${HOST_OUT_DIR}launcher_robot14   mariano_shared_objs_lib dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${HOST_OUT_DIR}launcher_robot16   mariano_shared_objs_lib dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
target_link_libraries(${HOST_OUT_DIR}terminator_host    mariano_shared_objs_lib dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)

#--------test--------
add_executable(${TEST_OUT_DIR}ArchivoIni_test            ${SRC_DIR}common/ArchivoIni.cpp)
target_link_libraries(${TEST_OUT_DIR}ArchivoIni_test            dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)
file(COPY ${SRC_DIR}common/prueba.ini     DESTINATION ${TEST_OUT_DIR})

add_executable(${TEST_OUT_DIR}logger_test            ${SRC_DIR}logger/logTest.cpp)
target_link_libraries(${TEST_OUT_DIR}logger_test            dsm_lib colaRemota_lib socket_lib dns_lib numerador_lib channel_common_lib application_lib middleware_lib logger_lib ipc_lib common_lib mariano_common_lib)

